<?php
/**
 * This is the template for action id `view`.
 */

/** @var yii\web\View $this */
/** @var \console\gii\controller\Generator $generator */
/** @var string $actionCamelID */
/** @var string $modelName */
$modelName = $generator->modelName;
?>
        $table = TableBuilder::instance(['id' => '<?= $generator->controllerCamelID . '_' . $actionCamelID ?>']);
        if ($this->isAjax) {
            $table->setQuery(function () {
                $queryParams = $this->filteredGet;
                $query = <?= $modelName ?>::query();
                $query->filterWhere([
                    'and',
                    [
                        'or',
                        //ID
                        ['=', 'id', isset($queryParams['keyword']) ? $queryParams['keyword'] : null],
                        //000
                    ],
                    //状态
                    ['status' => isset($queryParams['status']) ? $queryParams['status'] : null],
                ]);

                return $query;
            })->setOrderBy([
                'sort' => SORT_DESC,
                'id' => SORT_DESC,
            ])->setColumns([
                'id',
                'sort',
                'status' => function ($row) {
                    return H5::badge(
                        $row['status'] ? '正常' : '禁用',
                        $row['status'] ? 'primary' : 'danger'
                    );
                },
                'created_at',
                'updated_at',
            ]);
        } else {
            $table->setTitle('<?= $generator->sourceName ?>列表')
                ->setMaxHeight(750)
                ->setLimit(20)
                ->setTableHead([
                    $this->tableHead->field('id')->title('ID')->sort(),
                    $this->tableHead->field('sort')->title('排序')->editText('<?= $generator->controllerID ?>/sort')->width(120)->sort(),
                    $this->tableHead->field('status')->title('状态')->width(80),
                    $this->tableHead->field('created_at')->title('添加时间')->width(150),
                    $this->tableHead->field('updated_at')->title('上次更新')->width(150),
                    $this->tableHead->toolbar()->title('操作'),
                ])
                ->setToolbarCustom([
                    $this->toolbarCustom->modal()->title('新增')->route('<?= $generator->controllerID ?>/create')->height(450),
                ])
                ->setRowOperation([
                    $this->rowOperation->modal()->title('编辑')->route('<?= $generator->controllerID ?>/update')->height(450),
                ])
                ->setToolbarFilter([
                    'keyword' => $this->toolbarFilter->text()->label('关键词')->uiClass(['w-330', 'pr-3']),
                    'status' => $this->toolbarFilter->select()->label('状态')->options(['禁用', '正常'])->uiClass(['w-330', 'pr-3']),
                ]);
        }

        return $table->render();
